package com.ruoyi.yljf.controller.AppController;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.security.annotation.Anonymous;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.yljf.domain.Clock;
import com.ruoyi.yljf.service.IClockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 打卡Controller
 * 
 * @author metaee
 * @date 2025-02-14
 */
@Anonymous
@RestController
@RequestMapping("api/clock")
public class ApiClockController extends BaseController {
    @Autowired
    private IClockService clockService;

    /**
     * 查询打卡列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Clock clock) {
        startPage();
        List<Clock> list = clockService.selectClockList(clock);
        return getDataTable(list);
    }

    /**
     * 获取打卡详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(clockService.getById(id));
    }

    /**
     * 获取用户打卡记录
     */
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfoByUserId(@PathVariable("userId") Long userId) {
        Clock clock = new Clock();
        clock.setUserId(userId);
        return success(clockService.selectClockList(clock));
    }
}
